﻿using MediatR;
using SlaughterItem.Common.Domains.ListWeek2;
using SlaughterItem.Common.Dtos;
using SlaughterItem.Common.Infrastructures.Interfaces;
using SlaughterItem.Enum;

namespace GetSlaughterItem.API.Application.Commands.Week02.SlaughterCommands
{
    public class SlaughterMinShowHandler : IRequestHandler<SlaughterMinShowCommand, Result>
    {
        IBaseRepositoryGet<Slaughter> SlaughterRep;

        public SlaughterMinShowHandler(IBaseRepositoryGet<Slaughter> slaughterRep)
        {
            SlaughterRep = slaughterRep;
        }
        /// <summary>
        /// 批宰根据日期统计显示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Result> Handle(SlaughterMinShowCommand request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCode.Search };
            try
            {
                //var list = SlaughterRep.GetAll().ToList();

                //// 生产日期
                //if (request.SlaughterSDate != null)
                //{
                //    list = list.Where(x => x.SlaughterSDate >= request.SlaughterSDate).ToList();
                //}

                //list = list.OrderBy(x => x.SlaughterId).Skip((1 - 1) * 31).Take(31).ToList();

                //// 获取今日销售数据总量
                //SalesStatistics statistics = new SalesStatistics();
                //var lista = statistics.GetTodaySalesTotal(list);
                ////如果有数据就返回
                //if (list != null)
                //{
                //    result.Code = (int)CommonErrorCode.Success;
                //    result.Data = lista;
                //    result.Msg = "查询成功";
                //}
            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
    public class SalesStatistics
    {
        //public dynamic GetTodaySalesTotal(List<Slaughter> salesRecords)
        //{
        //    // 获取当前日期
        //    DateTime today = DateTime.Today;

        //    // 筛选出今天的屠宰记录
        //    var todaySalesRecords = salesRecords.Where(x => x.SlaughterSDate == today).ToList();

        //    // 计算今天今天的屠宰记录的数量
        //    var totalNum = todaySalesRecords.Sum(x=>x.SlaughterNum);
        //    // 计算今天今天的屠宰记录的重量
        //    var totalWeight = todaySalesRecords.Sum(x => x.SlaughterNum*120);

        //    return new
        //    {

        //        totalNum,
        //        totalWeight
        //    };
        //}
    }
}
